﻿using SIE.SCADA.Database.Interfaces;
using SIE.SCADA.SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SIE.SCADA.ZemtDemo.Common
{
    public class PgSqlAccess:ConfigBase,IDisposable
    {
        //private readonly string connectTemplete = "server ={0};database={1}; uid={2};pwd={3};Integrated Security={4};Connect Timeout={5};";
        public static string ConnectionString = Env.ConnectStr.Value;
        public override IDBClient GetClient()
        {
            var connectionConfig = new ConnectionConfig();
            connectionConfig.ConnectionString = ConnectionString;
            connectionConfig.DbType = SqlSugar.DbType.PostgreSQL;
            connectionConfig.InitKeyType = InitKeyType.Attribute;
            DBClient = CreateDBClient(connectionConfig);
            return DBClient;
        }

        protected override void Init()
        {
            ClientProviderString = "SIE.SCADA.SqlSugar.SmdcOrmClient,SIE.SCADA.SqlSugar.dll";
            ConfigProviderString = "SIE.SCADA.SqlSugar.ConnectionConfig,SIE.SCADA.SqlSugar.dll";
        }

        public void Dispose()
        {
            if(DBClient is SmdcOrmClient orm)
            {
                orm.SqlSugarClient?.Close();
                orm.SqlSugarClient?.Dispose();
            }
        }
    }
}
